package com.feng.common.api;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author Feng
 * @since 2021/10/24 12:39
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult {

    // 状态码
    private Integer code;
    // 消息
    private String msg;
    // 数据
    private Object data;

    public ResponseResult(ResultCode resultCode) {
        this(resultCode, null);
    }

    public ResponseResult(ResultCode resultCode, Object data) {
        this(resultCode.getCode(), resultCode.getMsg(), data);
    }

    public static ResponseResult success() {
        return success(null);
    }

    public static ResponseResult success(Object data) {
        return new ResponseResult(ResultCode.SUCCESS, data);
    }

    public static ResponseResult error(String errorMsg) {
        return new ResponseResult(ResultCode.ERROR.getCode(), errorMsg, null);
    }

    public static ResponseResult error() {
        return new ResponseResult(ResultCode.ERROR);
    }
}
